package com.woniu.airent.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.airent.dto.ArticleDto;
import com.woniu.airent.dto.ReplyDto;
import com.woniu.airent.mapper.ArticleMapper;
import com.woniu.airent.mapper.ReplyMapper;
import com.woniu.airent.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    @Autowired
    ReplyMapper replyMapper;

    @Override
    public PageInfo<ArticleDto> query(int currentPage, int pageSize, String keyWord, int status) {
        PageHelper.startPage(currentPage,pageSize);
        List<ArticleDto> article = articleMapper.selectArticle(keyWord,status);
        PageInfo<ArticleDto> pageInfo = new PageInfo<>(article);

        return pageInfo;
    }

    @Override
    @Transactional
    public int addArticle(ArticleDto article) {
        int result = articleMapper.insert(article);
        return result;
    }

    @Override
    public ArticleDto singleQuery(int id) {
        return articleMapper.selectSingle(id);
    }

    @Override
    @Transactional
    public int addReply(ReplyDto replyDto) {
        return replyMapper.insertReply(replyDto);
    }
}
